import 'package:flutter/material.dart';

/**
 * Widget Button使用
 */
main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HYHomePage(),
    );
  }
}

class HYHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('基础Widge'),
      ),
      body: HYHomeContent(),
      floatingActionButton: FloatingActionButton(
          child: Icon(Icons.add),
          onPressed: () {
            print('FloatingActionButton click');
          }),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
    );
  }
}

class HYHomeContent extends StatefulWidget {
  @override
  _HYHomeContentState createState() => _HYHomeContentState();
}

class _HYHomeContentState extends State<HYHomeContent> {
  @override
  Widget build(BuildContext context) {
    return ButtonDemo();
  }
}

class ButtonDemo extends StatelessWidget {
  const ButtonDemo({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        //1.RaisedButton:
        RaisedButton(
            child: Text('RaiseButton'),
            textColor: Colors.white,
            color: Colors.green,
            onPressed: () {
              print('RaiseButton click');
            }),
        //2.FlatButton
        FlatButton(
          child: Text('FlatButton'),
          textColor: Colors.black,
          color: Colors.orange,
          onPressed: () {
            print('FlatButton click');
          },
        ),
        //3.OutlineButton
        OutlineButton(
          child: Text('OutlineButton'),
          textColor: Colors.blue,
//          color: Colors.green,
          onPressed: () {
            print('OutlineButton click');
          },
        ),
        //4.FloatingActionButton
        //5.自定义button: 图标-文字-背景-圆角
        FlatButton(
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              Icon(
                Icons.favorite,
                color: Colors.red,
              ),
              Text('喜欢作者')
            ],
          ),
          color: Colors.yellow,
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
          onPressed: () {
            print('自定义图标click');
          },
        )
      ],
    );
  }
}


class ButtonExtensionDemo extends StatelessWidget {
  const ButtonExtensionDemo({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    //1.默认情况下button上下有一定的距离
    //2.Button变小: ButtonTheme
    //3.取出button的内边距
    return Column(
      children: [
        ButtonTheme(
//          minWidth: 30,
//          height: 10,
          child: FlatButton(
            color: Colors.orange,
            textColor: Colors.white,
            padding: EdgeInsets.all(0),
            materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
            child: Text('Flat button'),
            onPressed: () {},
          ),
        ),
        FlatButton(
          color: Colors.red,
          textColor: Colors.white,
          materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
          child: Text('Flat button'),
          onPressed: () {},
        ),
      ],
    );
  }
}